import os
# 必须先设置环境变量！
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'iot.settings')

import django
from django.core.asgi import get_asgi_application
django_asgi_app = get_asgi_application()  # 后加

from channels.routing import ProtocolTypeRouter, URLRouter
from . import routings

# 手动初始化Django（可选，仅在需要时添加）
django.setup()

application = ProtocolTypeRouter({
    "http": django_asgi_app,
    "websocket": URLRouter(routings.websocket_urlpatterns),
})
